<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<script type="text/javascript">
	$(function(){
		//获取导航栏
		HM.ajax("<%=request.getContextPath()%>/productServlet","method=getAllNav",function(data){
			if(data.code==1){
				var o = data.obj;
				var str = "";
				$.each(o, function(index,ele) {
					str+="<li class=\"active\"><a href=\"<%=request.getContextPath()%>/productServlet?method=getPageProduct&cid="+ele.cid+"&pagenum=1 \">"+ele.cname+"<span class=\"sr-only\">(current)</span></a></li>";
				});
				$("#cate_list").html(str);
			}
		});
	});
	//退出登录的函数
	function loginOut(){
		//发送请求,退出登录
		HM.ajax("<%=request.getContextPath()%>/userServlet","method=userLoginOut",function(data){
			if(data.code==1){
				location.href="index.jsp";
			}
		});
	}
	function search(){
		var a = $("#searchinput").val();
		location.href="<%=request.getContextPath()%>/view/product/list.jsp?search="+a+"&pagenum=1";
	}
</script>
<div class="container-fluid">
	<div class="col-md-4">
		<!--<img src="resources/img/logo.png" />-->
	</div>
	<div class="col-md-5">
		<img src="<%=request.getContextPath()%>/resources/img/header.png" />
	</div>
	<div class="col-md-3" style="padding-top:20px">
		<ol class="list-inline" id="login-menu" >
			<c:if test="${user == null}">
				<li><a href="<%=request.getContextPath()%>/login.jsp">登录</a></li>
				<li><a href="<%=request.getContextPath()%>/register.jsp">注册</a></li>
			</c:if>
			<c:if test="${user != null}">
				<li><a href="">欢迎您 ${user.name}</a></li>
				<li><a href="<%=request.getContextPath()%>/userServlet?method=userLoginOut">退出登录</a></li>
			</c:if>
			<li><a href="<%=request.getContextPath()%>/view/cart/list.jsp">购物车</a></li>
			<li><a href="<%=request.getContextPath()%>/orderServlet?method=getAllOrder&pagenum=1">我的订单</a></li>
		</ol>
	</div>
</div>
<!--
	时间：2018-07-29
	描述：导航条
-->
<div class="container-fluid">
	<nav class="navbar navbar-inverse">
		<div class="container-fluid">
			<!-- Brand and toggle get grouped for better mobile display -->
			<div class="navbar-header">
				<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
					<span class="sr-only">Toggle navigation</span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
				</button>
				<a class="navbar-brand" href="<%=request.getContextPath()%>/index.jsp">首页</a>
			</div>

			<!-- Collect the nav links, forms, and other content for toggling -->
			<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
				<ul class="nav navbar-nav" id="cate_list">

				</ul>
				<form class="navbar-form navbar-right" role="search">
					<div class="form-group">
						<input id="searchinput" type="text" class="form-control" placeholder="Search">
					</div>
					<button type="button" class="btn btn-default" onclick="search()">Submit</button>
				</form>

			</div>
			<!-- /.navbar-collapse -->
		</div>
		<!-- /.container-fluid -->
	</nav>
</div>